package org.telegram.bot.controller;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import jakarta.annotation.Resource;
import jakarta.servlet.http.HttpServletResponse;
import lombok.extern.slf4j.Slf4j;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;
import org.telegram.bot.domain.BotChatMember;
import org.telegram.bot.service.IBotChatMemberService;

import java.util.List;

/**
 * 群管理员Controller
 *
 * @author wyx
 * @date 2024-11-20
 */
@RestController
@RequestMapping("/bot/chatmember")
@Slf4j
public class BotChatMemberController extends BaseController
{
    @Resource
    private IBotChatMemberService botChatMemberService;

    /**
     * 查询群管理员列表
     */
    @PreAuthorize("@ss.hasPermi('bot:chatmember:list')")
    @GetMapping("/list")
    public TableDataInfo list(BotChatMember botChatMember)
    {
        startPage();
        List<BotChatMember> list = botChatMemberService.selectBotChatMemberList(botChatMember);
        return getDataTable(list);
    }

    /**
     * 导出群管理员列表
     */
    @PreAuthorize("@ss.hasPermi('bot:chatmember:export')")
    @Log(title = "群管理员", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, BotChatMember botChatMember)
    {
        List<BotChatMember> list = botChatMemberService.selectBotChatMemberList(botChatMember);
        ExcelUtil<BotChatMember> util = new ExcelUtil<BotChatMember>(BotChatMember.class);
        util.exportExcel(response, list, "群管理员数据");
    }

    /**
     * 获取群管理员详细信息
     */
    @PreAuthorize("@ss.hasPermi('bot:chatmember:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(botChatMemberService.selectBotChatMemberById(id));
    }

    /**
     * 新增群管理员
     */
    @PreAuthorize("@ss.hasPermi('bot:chatmember:add')")
    @Log(title = "群管理员", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody BotChatMember botChatMember)
    {
        return toAjax(botChatMemberService.insertBotChatMember(botChatMember));
    }

    /**
     * 修改群管理员
     */
    @PreAuthorize("@ss.hasPermi('bot:chatmember:edit')")
    @Log(title = "群管理员", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody BotChatMember botChatMember)
    {
        return toAjax(botChatMemberService.updateBotChatMember(botChatMember));
    }

    /**
     * 删除群管理员
     */
    @PreAuthorize("@ss.hasPermi('bot:chatmember:remove')")
    @Log(title = "群管理员", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(botChatMemberService.deleteBotChatMemberByIds(ids));
    }
}
